package com.dz.usersystem;

import java.lang.reflect.Array;
import java.util.Arrays;

//快速排序
public class QuiltSort {
    public static void main(String[] args) {
        int[] arr ={-9,78,0,23,-567,70};
        quickSort(arr,0,arr.length-1);
        System.out.println(Arrays.toString(arr));

    }

    public static void quickSort(int[] arr ,int left ,int right){
        int l =left;
        int r =right;
        int pivot = arr[(left+right) / 2];

        int temp;

        while (l < right) {

            while (arr[l] < pivot){
                l++;
            }

            while (arr[r] > pivot){
                r--;
            }

            if (l >= r){
                break;
            }

            temp=arr[l];
            arr[l]=arr[r];
            arr[r]=temp;

            if (arr[l] ==pivot){
                r--;
            }
            if (arr[r] ==pivot){
                l++;
            }


        }
        if (l==r){
            l++;
            r--;
        }

        if (left < r){
            quickSort(arr, left, r);
        }

        if(right > l){
            quickSort(arr,l,right);
        }


    }


}
